package com.cqc.other.juc.synchronize.demo4;

import java.util.concurrent.TimeUnit;

/**
 * @author cui
 * @date 2025/6/25 22:13
 * @description 锁重入
 **/
public class DataEntity {


    public synchronized void add1() {
        System.out.println("add1() threadName:" + Thread.currentThread().getName());
        add2();
    }

    public synchronized void add2() {
        System.out.println("add2()threadName:" + Thread.currentThread().getName());
    }

    /**
     * add1() add2() 日志都打印出来了，没有发生死锁，这就是锁重入
     * add1() threadName:main
     * add2()threadName:main
     */
    public static void main(String[] args) {
        DataEntity dataEntity = new DataEntity();
        dataEntity.add1();
    }

}
